//
//  APBaseViewController.m
//  AqualPolo
//
//  Created by dong on 2024/5/1.
//

#import "APBaseViewController.h"
#import "UIView+Gradient.h"
@interface APBaseViewController ()
@end

@implementation APBaseViewController

- (APNavigationBar *)naviBar{
    if (!_naviBar) {
        _naviBar = [[APNavigationBar alloc] init];
        _naviBar.delegate = self;
    }
    return _naviBar;
}



- (UIImageView *)backgroundImageView{
    if (!_backgroundImageView) {
        _backgroundImageView = [[UIImageView alloc] init];
        [self.view insertSubview:_backgroundImageView atIndex:0];
        [_backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
    }
    return _backgroundImageView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadGradientBackground:@[LYRGBColor(19, 78, 104),LYRGBColor(25, 15, 85)]];
    
}

- (void)backButtonDidClick{
    if (self.navigationController != nil) {
        [self.navigationController popViewControllerAnimated:true];
    }else{
        [self dismissViewControllerAnimated:false completion:nil];
    }
}

- (void)loadNaviBar{
    [self.view addSubview:self.naviBar];
    [self.naviBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view);
    }];
    
}

- (void)loadNaviBar2{
    [self.view addSubview:self.naviBar];
    [self.naviBar.backButton setImage:[UIImage imageNamed:@"back_2"] forState:UIControlStateNormal];
    [self.naviBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view);
    }];
    
   
}

- (void)loadBackground:(NSString *)imageName{
    if (imageName) {
        self.backgroundImageView.image = [UIImage imageNamed:imageName];
    }else{
        self.backgroundImageView.image = [UIImage imageNamed:@"login_bg"];
    }
}



- (void)loadGradientBackground:(NSArray *)gradientColors{
    [self.view setGradientBackgroundWithColors:gradientColors locations:@[@0,@1] startPoint:CGPointMake(0.5, 0) endPoint:CGPointMake(0.5, 1)];
}


@end
